package com.tarena.lbs.business.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.pojo.param.StoreParam;
import com.tarena.lbs.business.pojo.query.StoreQuery;
import com.tarena.lbs.business.pojo.vo.StoreVO;
import com.tarena.lbs.business.servcie.StoreService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "店铺相关功能接口")
@RestController
@Slf4j
public class StoreController {
    @Autowired
    private StoreService storeService;

    @Operation(summary = "查询店铺列表")
    @PostMapping("/admin/basic/store/getAll")
    public Result<PageResult<StoreVO>> pageList(@RequestBody StoreQuery query) throws BusinessException {
        log.info("查询店铺列表，入参:{}", query);
        PageResult<StoreVO> result = storeService.pageList(query);
        return new Result<>(result);
    }

    @Operation(summary = "新增店铺")
    @PostMapping("/admin/basic/store/save")
    public Result<Void> save(@RequestBody StoreParam param) throws BusinessException {
        storeService.save(param);
        return Result.success();
    }

    @Operation(summary = "更新店铺")
    @PutMapping("/admin/basic/store/update")
    public Result<Void> update(@RequestBody StoreParam param) throws BusinessException {
        storeService.update(param);
        return Result.success();
    }

    @Operation(summary = "删除店铺")
    @DeleteMapping("/admin/basic/store/delete/{id}")
    public Result<Void> delete(@PathVariable Integer id) throws BusinessException {
        storeService.delete(id);
        return Result.success();
    }

    @Operation(summary = "查询店铺详情")
    @GetMapping("/admin/basic/store/{id}")
    public Result<StoreVO> detail(@PathVariable("id") Integer storeId) throws BusinessException {
        StoreVO detail = storeService.detail(storeId);
        return new Result<>(detail);
    }
}